import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:fluwx/fluwx.dart';
import 'package:shopping_group/entity/widget_entity.dart';
import 'package:shopping_group/modle/person/ui/bank_list_page.dart';
import 'package:shopping_group/utils/image_utils.dart';
import 'package:shopping_group/utils/route_util.dart';
import 'package:shopping_group/utils/utils.dart';

import '../entity/rich_text_entity.dart';
import '../res/colors.dart';
import '../res/dimens.dart';
import '../utils/widget_utils.dart';
import 'button_progress_view.dart';

class ShowBottomSheet {
  static BuildContext showBottomZFBContent;
  static Future showBottomSheetView(BuildContext context,
      {String title,
      String content,
      String describe,
      Function onCilekListener}) {
    List<RichTextEntity> list = [];
    list
      ..add(RichTextEntity()
        ..backgroundColor = Colours.themeColor
        ..title = title
        ..textColor = Colours.title_white
        ..size = Dimens.FONT_SIZE_10)
      ..add(RichTextEntity()
        ..backgroundColor = Colours.title_white
        ..title = content
        ..textColor = Colours.text_2222
        ..size = Dimens.FONT_SIZE_15);
    return showModalBottomSheet(
        context: context,
        builder: (BuildContext buildContext) {
          return Container(
            alignment: FractionalOffset.centerLeft,
            height: 220,
            padding: const EdgeInsets.all(16),
            decoration: new BoxDecoration(
              color: Colors.white,
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                WidgetUtils.getTextColorView(
                    title, Colours.text_2222, Dimens.FONT_SIZE_20,
                    fontweight: FontWeight.w500),
                Padding(
                  child: WidgetUtils.getTextColorView(
                      describe, Colours.text_2222, Dimens.FONT_SIZE_15),
                  padding: const EdgeInsets.only(top: 8),
                ),
                Padding(
                    padding: const EdgeInsets.only(top: 8),
                    child: WidgetUtils.getRichTextView(list,
                        onCilekListener: onCilekListener)),
              ],
            ),
          );
        });
  }

  static Future showZfbView(BuildContext context,
      {String commplyName, String monney, Function onZFBTapStart}) {
    return showModalBottomSheet(
        isDismissible: false,
        context: context,
        builder: (BuildContext context) {
          showBottomZFBContent = context;
          return Container(
            height: MediaQuery.of(context).size.height / 2,
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Row(
                  children: <Widget>[
                    GestureDetector(
                      onTap: () {
                        _showTxView(context);
                      },
                      child: Icon(
                        Icons.close,
                        color: Colours.gray_cc,
                        size: 24,
                      ),
                    ),
                    Expanded(child: Container()),
                  ],
                ),
                SizedBox(
                  height: 16,
                ),
                Expanded(
                  child: Column(
                    children: <Widget>[
                      WidgetUtils.getTextColorView(
                          '福建利正集团有限公司', Colours.text_2222, Dimens.FONT_SIZE_16),
                      SizedBox(
                        height: 16,
                      ),
                      WidgetUtils.getTextColorView(
                          '¥ $monney', Colours.text_2222, Dimens.FONT_SIZE_45,
                          fontweight: FontWeight.w700),
                      SizedBox(
                        height: 32,
                      ),
                      Row(
                        children: <Widget>[
                          WidgetUtils.getTextColorView(
                              '付款方式', Colours.gray_cc, Dimens.FONT_SIZE_14),
                          Expanded(child: Container()),
                          Row(
                            children: <Widget>[
                              WidgetUtils.buildNetworkImageView(
                                  'https://static.jiujiupingou.com/Static/img/banklogo/6.png',
                                  height: 24,
                                  width: 24),
                              WidgetUtils.getTextColorView('农业银行储蓄卡(7865)',
                                  Colours.text_2222, Dimens.FONT_SIZE_14,
                                  overflow: TextOverflow.ellipsis),
                            ],
                          ),
                          Icon(
                            Icons.keyboard_arrow_right,
                            color: Colours.gray_cc,
                            size: 16,
                          )
                        ],
                      )
                    ],
                  ),
                ),
                ButtonProgressView.crateCupertinoView('立即付款',
                    horizontalPadding: 8,
                    blackColor: Colours.blue_be9, cupertinoCall: () {
                  onZFBTapStart();
                }),
                SizedBox(
                  height: 8,
                ),
                // Container(
                //   decoration: BoxDecoration(
                //     color: Colours.transparent_25,
                //   ),
                //   child: Image.asset(Utils.getImgPath('zhf_zf', format: 'png'),
                //       height: 24),
                // ),
                SizedBox(
                  height: 8,
                ),
              ],
            ),
          );
        });
  }

  static Future _showTxView(BuildContext context) async {
    showDialog(
        context: context,
        barrierDismissible: true,
        builder: (context) {
          return AlertDialog(
            title: Center(
              child: WidgetUtils.getTextColorView(
                '选择',
                Colours.text_2222,
                Dimens.FONT_SIZE_16,
              ),
            ),
            content: WidgetUtils.getTextColorView(
                '确定要放弃这次付款', Colours.text_2222, Dimens.FONT_SIZE_16),
            actions: <Widget>[
              FlatButton(
                  onPressed: () {
                    Navigator.of(context).pop('yes');
                  },
                  child: WidgetUtils.getTextColorView(
                      '确定', Colours.text_2222, Dimens.FONT_SIZE_16)),
              FlatButton(
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                  child: WidgetUtils.getTextColorView(
                      '取消', Colours.text_2222, Dimens.FONT_SIZE_16)),
            ],
          );
        }).then((var result) {
      if (null == result) {
        return;
      }

      if (result is String && 'yes' == result) {
        Navigator.of(context).pop();
      }
    });
  }

  static Future showTxView(BuildContext context) {
    List<WidgetEntity> list = [];
    list
      ..add(WidgetEntity()..title = '推广费提现')
      ..add(WidgetEntity()..title = '福利金提现');
    return showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return Container(
            alignment: FractionalOffset.centerLeft,
            height: 160,
            padding: const EdgeInsets.all(16),
            decoration: new BoxDecoration(
              color: Colors.white,
            ),
            child: Column(
              children: list.map((WidgetEntity entity) {
                return _txDepartmentName(entity, context);
              }).toList(),
            ),
          );
        });
  }

  static Future showWxShare(BuildContext context) {
    List<WidgetEntity> list = [];
    list
      ..add(WidgetEntity()..title = '分享微信')
      ..add(WidgetEntity()..title = '分享二维码');
    return showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
            child: Wrap(
              direction: Axis.horizontal,
              alignment: WrapAlignment.start,
              crossAxisAlignment: WrapCrossAlignment.start,
              children: list.map((WidgetEntity entity) {
                return _departmentName(entity);
              }).toList(),
            ),
          );
        });
  }

  static Widget _txDepartmentName(WidgetEntity entity, context) {
    return GestureDetector(
      onTap: (() {
        Navigator.of(context).pop();
        switch (entity.title) {
          case '推广费提现':
            RouteUtil.goParameter(BankListPage(
              txType: '推广费提现',
            ));
            break;
          case '福利金提现':
            RouteUtil.goParameter(BankListPage(txType: '福利金提现'));
            break;
          default:
        }
      }),
      child: Padding(
        padding: const EdgeInsets.only(right: 16, top: 8),
        child: Container(
          color: Colours.transparent,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              // ImageUtils.imageNetwork(
              //     'http://quanmp.oss-cn-shenzhen.aliyuncs.com/static/images/2login/signin_icon_wechat.png'),
              Padding(
                  padding: const EdgeInsets.only(top: 8),
                  child: Column(
                    children: <Widget>[
                      WidgetUtils.getTextColorView(
                          entity.title, Colours.text_2222, Dimens.FONT_SIZE_16),
                      SizedBox(
                        height: 16,
                      ),
                      WidgetUtils.drawDivider(),
                    ],
                  )),
            ],
          ),
        ),
      ),
    );
  }

  static Widget _departmentName(WidgetEntity entity) {
    return GestureDetector(
      onTap: (() {
        switch (entity.title) {
          case '分享微信':
            _shareText();
            break;
          case '分享二维码':
            _shareImage();
            break;
          default:
        }
      }),
      child: Padding(
        padding: const EdgeInsets.only(right: 16, top: 8),
        child: Container(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              ImageUtils.imageNetwork(
                  'http://quanmp.oss-cn-shenzhen.aliyuncs.com/static/images/2login/signin_icon_wechat.png'),
              Padding(
                padding: const EdgeInsets.only(top: 8),
                child: WidgetUtils.getTextColorView(
                    entity.title, Colours.text_91, Dimens.FONT_SIZE_15),
              ),
            ],
          ),
        ),
      ),
    );
  }

  static void _shareText() {
    String _text = "share text from fluwx";
    WeChatScene scene = WeChatScene.SESSION;
    shareToWeChat(WeChatShareTextModel(_text, scene: scene)).then((data) {
      print("-->$data");
    });

//    fluwx.sendAuth(WeChatSendAuthModel(scope: "snsapi_userinfo",state: "wechat_sdk_demo_test"));
  }

  static void _shareImage() {
    WeChatScene scene = WeChatScene.SESSION;
    String _imagePath =
        "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1534614311230&di=b17a892b366b5d002f52abcce7c4eea0&imgtype=0&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png";
    String _thumbnail = "assets://images/logo.png";
    shareToWeChat(WeChatShareImageModel(WeChatImage.network(_imagePath),
        thumbnail: WeChatImage.asset(_thumbnail)));
  }
}
